package com.qf.service;

/**
 * 资源类
 */
class Ticket{

    private int num = 100;
    //卖票
    public  void sale(){
        if(num == 0){
            System.out.println("不好意思没票了");
            return;
        }
        System.out.println("==开始卖票");
        num--;
        System.out.println("==剩余票数:" + num);
    }
}

/**
 * @author lixu
 */
public class LockDemo {

    //传统锁
    // 多线程情况下 保存线程安全 加个锁


    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                ticket.sale();
            }).start();
        }



    }
}
